package com.xiechuang.component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import brave.Tracer;
import org.springframework.stereotype.Component;

/**
 * @Description 自定义过滤：在链路数据中加上请求的操作人
 * @Author xiechuang
 * @Date 2021/12/22
 */
@Component
public class LoggerFilter extends ZuulFilter {

    @Autowired
    Tracer tracer;

    @Override
    public String filterType() {
        return FilterConstants.POST_TYPE;
    }

    @Override
    public int filterOrder() {
        return 900;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        tracer.currentSpanCustomizer().tag("operator", "xcc");
        System.out.println(tracer.currentSpan().toString());
        return null;
    }

}
